home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4743 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.3 KB

  1. Path: fozzie.sun3.iaf.nl!not-for-mail
  2. From: geert@fozzie.sun3.iaf.nl (Geert Bosch)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2
  4. Subject: Re: Hungarian notation
  5. Followup-To: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2
  6. Date: 31 Jan 1996 12:32:49 +0100
  7. Organization: La Calandre Infortunee
  8. Message-ID: <4enk11$svv@fozzie.sun3.iaf.nl>
  9. References: <30C40F77.53B5@swsbbs.com> <4cvu68$2jb@macaw.cyberport.com> <4d21og$iab@news.xmission.com> <4d2ok0$69s@beach.and.nl> <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca> <4e5k6o$aci@grid.direct.ca> <4ej0ds$sju@rational.rational.com> <Pine.HPP.3.91.960129201835.8755A-100000@mormon.cs.byu.edu>
  10. NNTP-Posting-Host: fozzie.sun3.iaf.nl
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. In article <Pine.HPP.3.91.960129201835.8755A-100000@mormon.cs.byu.edu> you wrote:
  14. : Maybe not.  But not everything falls under the hood of data abstraction.  
  15. : Somebody has to create the module/ADT/package/class first, and a good way 
  16. : to maintain it is to use a typedef or equivalent.  There are my 2c.
  17.  
  18. It's not a good way to do it that way. It's something like "I'm using the
  19. name My_ADT, but I *know* it's unsigned long, so when I need to I just
  20. break the abstraction". So you're just hiding the implementation details
  21. a little and the original writer of the ADT never knows if someone depends 
  22. on certain internals.
  23.  
  24. If you really want to break things that way in Ada, you can use an 
  25. 'Unchecked_Conversion' which is about the same as a typecast in C.
  26. However, when most Ada-programmers (including me) read code they'll go
  27. in alert-mode when they encounter 'with Unchecked_Conversion' at the
  28. top of your package. When they see you're using it to break the ADT,
  29. your code will be labeled as not maintainable: if the implementation is
  30. being changed, your package will be broken. When the size of the ADT
  31. remains the same, you might not even notice it, except of course for
  32. run-time problems.
  33.  
  34. So, what's the right way to do this? If you're the maintainer of 
  35. the code and need to change it and you don't have to change the 
  36. interface and the changed implementation is consistent with the
  37. specifications in all regards, then you just change the original
  38. package implementation. Since that's the only place that is dependend
  39. on the internals of the ADT you'll not break anything else.
  40.  
  41. But what if this isn't the case, or if you don't have access to
  42. the source? When the ADT is a tagged abstract data type, you can
  43. extend it and override existing operations on the type. As long
  44. as you don't have to switch between implementations at *runtime*,
  45. you do not have the overhead of dispatching calls. This is one of
  46. the reasons to implement ADT's with tagged types when extension
  47. is important.
  48.  
  49. If the ADT is not a tagged type and you cannot change the 
  50. implementation of the original type (because it doesn't conform
  51. to the old specs for example) the best way to solve the problem
  52. is by implementing a child package of the original parent package.
  53. That way you can view the internals of the ADT and create a new
  54. ADT based on the original one. Of course when the parent changes
  55. the implementation, the child needs to be changed too. The
  56. difference is however that the compiler will catch any inconsistencies
  57. which might go unnoticed when using C type-casts or unchecked 
  58. conversions.
  59.  
  60. For all methods described above you'll not silently break any 
  61. existing code. If you think that the scheme above is too 
  62. complicated for that goal, think about this: if your package 
  63. specification is good, you'll only change the implementation. Period.
  64.  
  65. When you need to change the interface and all code depending on the ADT
  66. is under your control (one person or small team developing software),
  67. you just change the specification and make any changes that are needed
  68. in packages using the ADT.  The compiler will help you doing this by
  69. catching all type inconsistencies that may arise.
  70.  
  71. The only place were the other methods make much sense is when
  72. the code is used in large projects or when the code is used in
  73. many projects and has a long life-time. In these cases silently
  74. breaking code when changing the specification is unacceptable, and
  75. hunting through all code depending on the ADT for implementation
  76. dependencies is not feasible. These are the places were type-extension
  77. and package-extension are important.
  78.  
  79. Greetings,
  80.    Geert
  81.  
  82. -- 
  83. E-Mail: geert@sun3.iaf.nl 
  84.  Phone: +31-53-4303054
  85.